package com.example.demo.common;

import com.example.demo.entity.UserEntity;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public class UserSessionTools {
    public static UserEntity getLoginUser(HttpServletRequest req) {
        HttpSession session = req.getSession(false);
        Object userObj = null;
        if (session != null && (userObj = session.getAttribute(ApplicationVariable.SESSION_KEY_USERINFO)) != null) {
            return (UserEntity) userObj;
        }
        return null;
    }
}
